/*
 *@本JS功能：班级管理
 *@本js作者：杨锡君
 *@编写时间：2017年10月31日
 */
$(function() {
    var Alert1 = new Alert();
    var confirm1 = new Confirm();
    var loading1 = new Loading();
    loading1.init();
    var $chapterList = $("#chapterList");
    var $iconfont = $(".iconfont");
    var $processInfo =  $(".processInfo");
    var $processed = $(".processed");
    var $clearProcessBtn = $(".clearProcessBtn");
    var $showSection = $(".showSection");
    var $mb = $(".mb");
    var $mainContents = $(".mainContents");
    function homeworkEvaluation(opt){
        var fun = "";
        if(opt.taskFraction != "undefined" && opt.taskFraction != "无" ){
            fun = opt.taskFraction;
        }else{
            fun = opt.taskSoruce;
        }
        if(fun == "undefined"){
            fun = 0;
        }
        return "<div class=\"popup\" style=\"display: block; width: 504px;\">"
            +"<div class=\"popup_box\">"
            +"<div class=\"popup_contenthead\">作业评价<img class=\"popup_img\" src=\"pc/images/ico_alertDel.png\"></div>"
            +"<div class=\"popup_content\">"
            +"<div style=\"height: auto;min-height: 34px\"><i>作业名称&ensp;:&ensp;</i><span>"+ opt.homeworkName +"</span></div>"
            +"<div><i>作业评分&ensp;:&ensp;</i><span>"+ fun +"</span></div>"
            +"<div><i>作业评价&ensp;:&ensp;</i><span>"+ opt.submitContent +"</span></div>"
            +"</div>"
            +"<div class=\"clear\"></div>"
            +"<div class=\"popup_btns\">"
            +"<a class=\"popup_confirm exportBtns hover-btn\">确定</a>"
            +"</div>"
            +"<div class=\"clear\"></div>"
            +"</div>"
            +"</div>";
    }
    function homework(opt){
        return "<div class=\"pophomework\" >"
            +"<div class=\"popup_box\">"
            +"<div class=\"popup_contenthead\">上传作业<img class=\"popup_img\" src=\"pc/images/ico_alertDel.png\"></div>"
            +"<form id=\"upHomework\" onsubmit=\"return false;\" method=\"post\" enctype=\"multipart/form-data\">"
            +"<div class=\"popup_content\">"
            +"<label class=\"fileBtn\" for=\"file\">点击选择文件</label>"
            +"<input type=\"file\" name=\"file\" id=\"file\" style=\"display: none;\" />"
            +"<input type=\"hidden\" name=\"chapterNum\" id=\"chapterNum\" value="+ opt.chapterNum +" />"
            +"<input type=\"hidden\" name=\"courseId\" id=\"courseId\" value="+ opt.courseId +" />"
            +"<input type=\"hidden\" name=\"taskType\" id=\"taskType\" value=\"1\" />"
            +"<div class=\"fileName\"></div>"
            +"</div>"
            +"<div class=\"popup_btn\">"
            +"<button type=\"submit\" class=\"popup_confirm exportBtn exportBtnHome hover-btn\">确定</button>"
            +"<a class=\"popup_close exportCancle hover-btn\">取消</a>"
            +"</div>"
            +"<div class=\"clear\"></div>"
            +"</form>"
            +"</div>"
            +"</div>";
    }
    var num =0;
    function chapterListModel(opt,url,stuUrl){
        var taskAddress = opt.taskAddress;
        if(taskAddress == ""){
            taskAddress = 1;
        }
        var taskFraction =opt.taskFraction;
        // if(taskFraction == undefined||taskFraction == null){
        //     taskFraction = "暂无";
        // }
        var submitContent = opt.submitContent;
        if(submitContent == undefined||submitContent == null){
            submitContent = "暂无";
        }
        num++;
        var str = "";
        var str1 = "";
        var str2 = "";
        var str3 = "";
        if(opt.addTestMark == 2){
            str = "<li>"
                +"<a data-value=\"0\" class=\"oneChapter\"  data-chapternum="+ opt.chapterNum +" href=\"javascript:;\">"
                +"<div><span class=\"down\">"+ opt.chapterNum +"-"+ opt.chapterName +"</span></div>"
                +"</a>"
                +"<ul>";
        }else{
            str = "<li>"
                +"<a data-value=\"0\" class=\"oneChapter\"  data-chapternum="+ opt.chapterNum +" href=\"javascript:;\">"
                +"<div><span class=\"down\">"+ opt.chapterNum +"-"+ opt.chapterName +"&ensp;<img src=\"pc/images/ico_hadLab.png\"></span></div>"
                +"</a>"
                +"<ul>";
        }

        str1 = "<li>"
            +"<a href=\"javascript:;\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.coursewareNameHtml +"' data-value=\"1\" class=\"courseware\">学习课件<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ url+opt.coursewareName +"' title=\"下载\" alt=\"下载\" class=\"download downloadTea fr\" />"
            +"</a>"
            +"</li>";
        if(result.roleId == 2){
            str1 += "<li>"
                // +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.courseMaterialName +"'  class=\"courseMaterial\">备课材料<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ url+ opt.courseMaterialName +"' title=\"下载\" alt=\"下载\" class=\"download downloadTea fr\" /></a>"
                +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.courseMaterialName +"'  class=\"courseMaterial\">备课材料</a>"
                +"</li>";
            str1 +=	"<li>"
                +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.homeworkNameHtml +"'   class=\"homework\">课后作业"
                +"<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ url+ opt.homeworkNameHtml +"' title=\"下载\" alt=\"下载\" class=\"download fr\" />"
                // +"<img src=\"pc/images/ico_homework.png\"  data-chapternum="+ opt.chapterNum +"  data-courseid="+ opt.courseId +"  data-chapterid="+ opt.chapterId +" title=\"上传\" class=\"uploadFile fr\" alt=\"上传\" />"
                +"</a>"
                +"</li>";
        }else{
            if(opt.taskAddress != "" && opt.taskAddress != undefined && opt.taskFraction != "" && opt.taskFraction != undefined){
                str1 +=	"<li>"
                    +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.homeworkNameHtml +"'  mark='3' class=\"homework\">课后作业(已评价)"
                    +"<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ stuUrl+ opt.homefileName +"' title=\"下载\" alt=\"下载\" class=\"download fr\" />"
                    // +"<img src=\"pc/images/ico_homework.png\"  data-chapternum="+ opt.chapterNum +"  data-courseid="+ opt.courseId +"  data-chapterid="+ opt.chapterId +" title=\"上传\" class=\"uploadFile fr\" alt=\"上传\" />"
                    +"</a>"
                    +"</li>";
            }else if(opt.taskAddress == "" || opt.taskAddress == undefined){
                str1 +=	"<li>"
                    +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.homeworkNameHtml +"'  mark='1'   class=\"homework\">课后作业(<em>未提交</em>)"
                    // +"<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ url+ opt.homeworkNameHtml +"' title=\"下载\" alt=\"下载\" class=\"download fr\" style='display: none!important;' />"
                    // +"<img src=\"pc/images/ico_homework.png\"  data-chapternum="+ opt.chapterNum +"  data-courseid="+ opt.courseId +"  data-chapterid="+ opt.chapterId +" title=\"上传\" class=\"uploadFile fr\" alt=\"上传\" />"
                    +"</a>"
                    +"</li>";
            }else{
                str1 +=	"<li>"
                    +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.homeworkNameHtml +"'  mark='2'   class=\"homework\">课后作业(未评价)"
                    // +"<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ stuUrl+ opt.homefileName +"' title=\"下载\" alt=\"下载\" class=\"download fr\" />"
                    // +"<img src=\"pc/images/ico_homework.png\"  data-chapternum="+ opt.chapterNum +"  data-courseid="+ opt.courseId +"  data-chapterid="+ opt.chapterId +" title=\"上传\" class=\"uploadFile fr\" alt=\"上传\" />"
                    +"</a>"
                    +"</li>";
            }

        }
        str2 = "<li>"
            // +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.testDocName +"'   class=\"testDoc\">实验手册<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ url+ opt.testDocName +"'  title=\"下载\" alt=\"下载\" class=\"download  downloadTea fr\" /></a>"
            +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.testDocName +"'   class=\"testDoc\">实验手册</a>"
            +"</li>"
            +"<li>"
            +"<a href=\"javascript:;\" data-value=\"1\"  data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-src='"+ url+ opt.videoName +"'  class=\"video\">学习视频<img src=\"pc/images/ico_downloadFile.png\" data-src='"+ url+ opt.videoName +"'  title=\"下载\" alt=\"下载\" class=\"download downloadTea  fr\" /></a>"
            +"</li>"
            +"<li>"
            +"<a href=\"javascript:;\"   data-value=\"1\" data-courseid="+ opt.courseId +"   data-chapternum="+ opt.chapterNum +"  data-chapterid="+ opt.chapterId +"   data-video='"+ url+ opt.videoName +"'  class=\"enterLab\">进入实验</a>"
            +"</li>";
        if(opt.packageFile != "" && opt.packageFile != undefined && opt.packageFile != null){
            str3 = "<li>"
                +"<a href=\"javascript:;\" data-value=\"1\" class=\"packageFile\">课程材料<img src=\"pc/images/ico_downloadFile.png\" title=\"下载\" alt=\"下载\" data-src='"+ url+ opt.packageFile +"' class=\"download fr\" /></a>"
                +"</li>"
                +"</ul>"
                +"</li>";
        }else{
            str3 = "</ul>"
                +"</li>";
        }

//			理论
        if(opt.addTestMark == 2){
            return str + str1 + str3;
        }
//			实验
        if(opt.addTestMark == 1){
            return str + str2 + str3;
        }
//			理论加实验
        if(opt.addTestMark == 3){
            return str + str1 + str2 + str3;
        }

    }
    function homeworkShow(opt) {
        var str = '<div style="background: #fff;" class="editSection">' +
            '<div class="fl" style="margin: 20px 0 0 0;text-align: left">' +
            opt+
            '</div>' +
            '</div>';
        return str;
    }
    function homeworkShows(opt,chapterId) {
        var str = '<div style="background: #fff;" class="editSection">' +
            '<div class="fl" style="margin: 20px 0 0 0;text-align: left">' +
            '<h4 data-chapterid="'+ chapterId +'" class="saveMar">提交</h4>' +
            '<h4 data-chapterid="'+ chapterId +'" class="saveHome">保存</h4><span class="clear"></span>' +
            opt+
            '</div>' +
            '</div>';
        return str;
    }
    // 学生端评分
    function homeworkShows2(opt,chapterId) {
        var str =   '<div style="background: #fff;" class="editSection">' +
            '   <div class="fl" style="margin: 20px 0 0 0;text-align: left; overflow: auto; height: 620px">' +
            '<div class="inputRight" style="border-bottom: solid 1px #333; margin: 0 32px; padding-bottom: 20px; margin-bottom: 10px;">' +
            '   <label for="labScore">作业评分:&ensp;</label>' +
            '   <span id="labScore" style="margin-right: 100px;"></span>'+
            '   <label class="hide" for="labScore">作业评价:&ensp;</label>'+
            '   <b class="levelBg hide"><b class="levelTop"></b><img src="pc/images/ico_level.png" alt=""></b>'+
            '   <i class="levels hide"></i>'+
            '   <div class="clear"></div>'+
            '   <div style=" margin-top: 10px; ">'+
            '       <label class="hide" for="labScore" style="vertical-align: top; float: left;">作业评语:&ensp;</label>'+
            '       <span id="ExperimentTextarea" style="float: left; width:93%; overflow: auto; text-overflow: unset; white-space: initial;"></span>'+
            '   </div>'+
            '  </div>'+
            '       <h4 data-chapterid="'+ chapterId +'" class="saveMar">提交</h4>' +
            '       <h4 data-chapterid="'+ chapterId +'" class="saveHome">保存</h4><span class="clear"></span>' +
            opt+
            '   </div>' +
            '</div>';
        return str;
    }
    var myCourse = {
        init:function(){
            this.bindEvent();
        },
        bindEvent:function(){
            var self = this;
            self.getData();
            self.getProcess();
            $clearProcessBtn.off("click").click(function(){
                var courseId =  result.paramData.courseId;
                self.clearProcess(courseId);
            });
            self.processHide();
        },
        processHide:function () {
            // 进度隐藏
            $(".moveTop").off("click").click(function(){
                $(".mainContent").hide();
                $(".showProcess").show();
                $(".courseChapterList,.fileShowSection").height(830);
                $(".chapterDetail").height(790);
                $(".moveDown").show();
                $(".moveTop").hide();
                $(".homeShowBox").height(790);
            });
            $(".moveDown").off("click").click(function(){
                $(".mainContent").show();
                $(".showProcess").hide();
                $(".courseChapterList,.fileShowSection").attr("style","");
                $(".chapterDetail").attr("style","");
                $(".moveDown").hide();
                $(".moveTop").show();
                $(".homeShowBox").height(690);
            });
        },
        clearProcess:function(courseId){
//			清楚进度
            var self = this;
            var jsonStr = JSON.stringify({
                "courseId":courseId
            });
            $.ajax({
                type:"post",
                url:"emptyProcess",
                async:true,
                data:{
                    "jsonStr":jsonStr
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    if(msg.result == "success"){
                        Alert1.content = "清除成功";
                        Alert1.success = function(){
                            self.getProcess();
                        };
                        Alert1.init();
                        Alert1.show();
                    }
                }
            });
        },
        getData:function(){
//			获取头部信息，章节列表
            var self = this;
            var jsonStr = JSON.stringify({
                "courseId":result.paramData.courseId
            });
            $.ajax({
                type:"post",
                url:"skipCourseStudyDetail",
                async:true,
                data:{
                    "jsonStr":jsonStr
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    $iconfont.html(msg.courseDetail.courseTitle);
                    $iconfont.css({"color":msg.courseDetail.courseColer,"border-color":msg.courseDetail.courseColer});
                    $iconfont.siblings("p").html(msg.courseDetail.courseName);
                    $iconfont.siblings("p").attr("title",msg.courseDetail.courseName);
                    // if(msg.process != 0){
                    //    $(".preChapter").html("上一章&emsp;"+(msg.process)+"-"+msg.chapterList[msg.process-1].chapterName);
                    // }
                    // if(msg.process < msg.chapterList.length-1){
                    //    $(".nextChapter").html("下一章&emsp;"+(msg.process+2)+"-"+msg.chapterList[msg.process+1].chapterName);
                    // }
                    var str = "";
                    var downIsOk = msg.donwload_juirs;
                    if(msg.chapterList.length!=0){
                        $.map(msg.chapterList, function(opt) {
                            str += chapterListModel(opt,msg.url,msg.stuUrl);
                        });
                        $chapterList.append(str);
                        if(downIsOk == 1){
                            $(".download").remove();
                        }
                        for(var j =0;j<$(".oneChapter").length;j++){
                            for(var i=0;i<$(".oneChapter").eq(j).next().children("li").length;i++){
                                $(".oneChapter").eq(j).next().children("li").eq(i).append("<i>"+  $(".oneChapter").eq(j).attr("data-chapternum")+"-"+ (i+1) +"."+"</i>");
                            }
                        }

                    }


                    self.stuiedEvent(msg.studyList);
                    self.selectEvent();
                    self.btnFun(msg.url,msg.stuUrl,msg.chapterList);
                    self.authority(msg.roleId);
                }
            });

        },
        authority:function(roleId){
//			权限
            if(roleId == 1){
                $(".downloadTea").remove();
                $(".clearProcessBtn").remove();
            }else if(roleId == 2){
                $(".uploadFile").remove();
            }else{
                $(".download").remove();
                $(".clearProcessBtn").remove();
                $(".uploadFile").remove();
                $(".enterLab").off("click");
                $(".enterLab").removeClass("enterLab");
            }
        },
        stuiedEvent:function(arr){
//			学习过的章节变色
            $.map(arr, function(opt) {
                $(".oneChapter[data-chapternum="+ opt.chapterNum +"]").attr("data-value","1");
            });

        },
        btnFun:function(url,stuUrl,chapterList){
//			章节中按钮方法
//			查看
            var self = this;
            function videoRemove(){
                //去除video标签
                if($(".showVideo").length!=0){
                    $(".showVideo").remove();
                }
            }
//			学习课件
            $(".courseware").off("click").click(function(){
                videoRemove();
                $(".editSection").remove();
                var that = $(this);
                self.addProcess({"chapterNum":Number($(this).attr("data-chapternum")),"courseId":Number($(this).attr("data-courseid"))});
                $(this).parent().parent().siblings("a").attr("data-value","1");
                if($(this).attr("data-src").indexOf(".pdf") != -1){
                    $.ajax({
                        type: "post",
                        url: "addCourseOrExpreCount",
                        async: true,
                        data: {
                            "jsonStr": JSON.stringify({"mark":1,"courseId":Number(that.attr("data-courseid"))})
                        },
                        success: function (msg) {
                        }
                    });
                    $showSection.attr("src","pc/js/extends/generic/web/viewer.html?file="+$(this).attr("data-src"));
                    $showSection.load(function () {
                        $showSection.contents().find("link").remove();
                        $showSection.contents().find("title").before("<link href='viewer.css' rel='stylesheet'>");
                    });
                }else{
                    $showSection.attr("src","pc/page/noResourceShow.html");
                }

            });
            //备课材料
            $(".courseMaterial").off("click").click(function(){
                videoRemove();
                $(".editSection").remove();
                if($(this).attr("data-src").indexOf(".html") != -1){
                    $showSection.attr("src",$(this).attr("data-src"));
                }else{
                    $showSection.attr("src","pc/page/noResourceShow.html");
                }

            });
            //课后作业
            $(".homework").off("click").click(function(){
                videoRemove();
                var that = $(this);
                $(".editSection").remove();
                var chapterId = Number($(this).attr("data-chapterid"));
                var json = JSON.stringify({"chapterId":chapterId,"courseId":Number(result.paramData.courseId),"chapterNum":Number($(this).attr("data-chapternum"))});
                // 新增需求获取当前课程json
                var courseJson = ''
                for(var i = 0; i < chapterList.length; i++){
                    if(chapterList[i].chapterId == chapterId){
                        courseJson = chapterList[i]
                    }
                }
                $.ajax({
                    type: 'post',
                    url: 'skipCourseStudyDetailByChpterId',
                    async: true,
                    data: {
                        "jsonStr": json
                    },
                    success: function (msg) {
                        msg = JSON.parse(msg);
                        if (msg.result == "success") {
                            if (msg.chapterMsg.taskHtml != '' && msg.chapterMsg.taskHtml != undefined && msg.chapterMsg.taskHtml != null) {
                                var str = '';
                                var str2 = '';
                                // 1 学生 2 老师
                                if(result.roleId == 1){
                                    console.log(courseJson.taskAddress)
                                    if(courseJson.taskAddress != '' && courseJson.taskAddress != undefined){
                                        str = homeworkShows2(unescape(msg.chapterMsg.taskHtml),chapterId);
                                    }else{
                                        str = homeworkShows(unescape(msg.chapterMsg.taskHtml));
                                    }
                                    str = str.replace(/\(&emsp;&emsp;\)/g,"(<input maxlength='50' class=\"answerInt others\" type=\"text\">)");
                                    str = str.replace(/\(\+\)/g,"(<input maxlength='50' class=\"answerInt others\" type=\"text\">)");

                                    // 新增修改
                                    $(".fileShowSection").append(str);
                                    $("#labScore").html(courseJson.taskSoruce);
                                    $('.levels').html(courseJson.taskFraction)
                                    $(".levelTop").css("width",courseJson.taskSoruce+"%");
                                    if(courseJson.lable == ''){
                                        $("#ExperimentTextarea").html('无')
                                    }else{
                                        $("#ExperimentTextarea").html(courseJson.lable)
                                    }
                                    $(".shortAnswer").show();
                                    if (msg.chapterMsg.answerList != [] && msg.chapterMsg.answerList != undefined && msg.chapterMsg.answerList != null) {
                                        $.map(msg.chapterMsg.answerList, function(opt) {
                                            var ars = opt.ansquesContent.split(",");
                                            $.each($(".questionBox[data-questionid="+ opt.questionId +"]").find(".answerInt"), function(key) {

                                                $(this).val(ars[$(this).index()]);
                                            });
                                        });
                                    }
                                    maxLengthLimit.init("answerInt");
                                    if(that.attr("mark")!=undefined){
                                        if(that.attr("mark") == 3){
                                            $(".saveHome,.saveMar").hide();
                                            $(".shortAnswer").attr("disabled",true);
                                            $(".answerInt").attr("disabled",true);
                                            $(".shortAnswer").css("background","#fff");
                                            $(".answerInt").css("background","#fff");
                                            $(".homeShowBox").css("overflow","visible");
                                            if($(".fileShowSection ").height()>710){
                                                $(".homeShowBox").css("height","790px");
                                            }else{
                                                $(".homeShowBox").css("height","690px");
                                            }
                                        }
                                    }
                                    $(".saveHome").off("click").click(function () {
                                        var arr = [];
                                        for(var i = 0;i<$(".questionBox").length;i++){
                                            var ans = "";
                                            for(var j = 0;j<$(".questionBox").eq(i).find(".answerInt").length;j++){
                                                if(j == $(".questionBox").eq(i).find(".answerInt").length-1){
                                                    ans+=$(".questionBox").eq(i).find(".answerInt").eq(j).val();
                                                }else{
                                                    ans+=$(".questionBox").eq(i).find(".answerInt").eq(j).val()+",";
                                                }

                                            }
                                            var str = { "questionId": Number($(".questionBox").eq(i).attr("data-questionid")), "ansquesContent":ans,"questionType":$(".questionBox").eq(i).attr("data-questiontype"),"questionSource":$(".fen").eq(i).html()};
                                            arr.push(str);
                                        }
                                        $(".showText").remove();
                                        $.each($(".answerInt"),function (opt) {
                                            $(this).after('<b class="showText">'+ $(this).val() +'</b>')
                                        });
                                        var string = $(".editSection").html();
                                        var json = JSON.stringify({
                                            "chapterNum":that.attr("data-chapternum"),
                                            "courseId":that.attr("data-courseid"),
                                            "mapList":arr
                                        });
                                        loading1.show();
                                        $.ajax({
                                            type: "post",
                                            url: "saveStuHomePractice",
                                            async: true,
                                            data:{
                                                "jsonStr":json
                                            },
                                            success: function (msg) {
                                                loading1.hide();
                                                msg = JSON.parse(msg);
                                                if(msg.result == "success"){
                                                    Alert1.content = "保存成功";
                                                    Alert1.init();
                                                    Alert1.show();
                                                }else{
                                                    Alert1.content = msg.failMsg;
                                                    Alert1.init();
                                                    Alert1.show();
                                                    return false;
                                                }
                                            }
                                        });
                                    });
                                    $(".saveMar").off("click").click(function () {
                                        var arr = [];
                                        for(var i = 0;i<$(".questionBox").length;i++){
                                            var ans = "";
                                            for(var j = 0;j<$(".questionBox").eq(i).find(".answerInt").length;j++){
                                                if(j == $(".questionBox").eq(i).find(".answerInt").length-1){
                                                    ans+=$(".questionBox").eq(i).find(".answerInt").eq(j).val();
                                                }else{
                                                    ans+=$(".questionBox").eq(i).find(".answerInt").eq(j).val()+",";
                                                }

                                            }
                                            var str = { "questionId": Number($(".questionBox").eq(i).attr("data-questionid")), "ansquesContent":ans,"questionType":$(".questionBox").eq(i).attr("data-questiontype"),"questionSource":$(".fen").eq(i).html()};
                                            arr.push(str);
                                        }
                                        $(".showText").remove();
                                        $.each($(".answerInt"),function (opt) {
                                            $(this).after('<b class="showText">'+ $(this).val() +'</b>')
                                        });
                                        var string = $(".editSection").html();
                                        var json = JSON.stringify({
                                            "chapterNum":that.attr("data-chapternum"),
                                            "courseId":that.attr("data-courseid"),
                                            "chapterId":that.attr("data-chapterid"),
                                            "taskType":1,
                                            "optionSource":0,
                                            "judgeSource":0,
                                            "manyOptionSource":0,
                                            "mapList":arr,
                                            "htmlStr":escape(string),
                                            "cssStr":'@charset "utf-8";button:focus,input,input:focus,select,textarea:focus{outline:0}body,dd,dl,dt,form,h1,h2,h3,h4,h5,h6,input,li,ol,p,textarea,ul{margin:0;padding:0}select::-ms-expand{display:none;}select{border:1px solid #dcd9d9;appearance:none;-moz-appearance:none;-webkit-appearance:none;background:url(../../images/select.gif) right 10px center no-repeat #FFF}body,html{width:100%}label{font-size:16px!important;}.popup_content{font-size:16px!important;}body{font-size:16px;line-height:1.7;font-family:"Microsoft YaHei",simhei;color:#333;background-color:#DFDFDF;}input,select,textarea{color:#333;outline:none;}input{border:1px solid #dfdfdf;}input[type=checkbox]{-webkit-appearance:none;appearance:none;width:14px;vertical-align:middle;height:14px;margin:0;cursor:pointer;background:#fff;border:1px solid #a0a0a0;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:3px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:relative;}input[type=checkbox]:active,input[type=radio]:active{border-color:#a0a0a0;background:#fff;}input[type=checkbox]:hover{border-color:#a0a0a0;-webkit-box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);}input[type=checkbox]:checked,input[type=radio]:checked{background:#fff;}input[type=checkbox]:checked::after{content:url(../../images/ico_ok.png);display:block;position:absolute;top:-2px;left:2px;}input[type=checkbox]:focus{outline:none;border-color:#a0a0a0;}input[type=text]:focus{outline:none;}input:-webkit-autofill{-webkit-box-shadow:0 0 0px 1000px white inset;}ul,ol{list-style:none;}a{text-decoration:none;color:#333;font-size:16px}a:visited{color:#333;}a:hover,a:active,a:focus{color:#333;}em,i{font-style:normal}b,strong{font-weight:normal;}.fl{float:left}.fr{float:right}.clear{clear:both;height:0;overflow:hidden;}img{font-size:0;display:block;overflow:hidden;}table{table-layout:fixed;}td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}::-webkit-input-placeholder{color:#999999;}:-moz-placeholder{color:#999999;}::-moz-placeholder{color:#999999;}:-ms-input-placeholder{color:#999999;}.masking,.mb{position:fixed;width:100%;height:100%;z-index:0;background:rgba(0,0,0,0.7);top:0;left:0;display:none;}.iconfont{margin-bottom:0;font-size:36px;}.mainContent{padding:0 0 0 25px;width:auto;margin-top:10px;background:#fff;height:110px;position:relative;}.courseTitleBox{width:110px;height:110px;margin-right:25px;}.courseTitleBox p{font-size:14px;width:100%;text-align:center;line-height:32px;height:32px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}.processBox{height:110px;width:75%;}.btnBox{width:10%;}.clearProcessBtn{margin:40px auto 0;}.processBoxes{width:100%;height:84px;margin:auto;}.processInfo{font-size:14px;margin-top:26px;}.processBar{height:12px;width:100%;border-radius:20px;background:#eeeeee;margin-top:8px;position:relative;}.processed{width:0;background:#58a9ea;height:100%;border-radius:20px;}.processShowSome{margin-top:12px;font-size:14px;color:#d0d0d0}.mainContents{width:auto;margin-top:10px;}.courseChapterList{width:20.34%;height:620px;background:#fff;}.fileShowSection{width:79.16%;height:620px;margin-left:0.5%;background:#fff;position:relative;}.courseTitle{height:39px;padding-left:40px;line-height:39px;border-bottom:1px solid #DFDFDF;background:url(../../images/ico_courseList.png) left 12px center no-repeat;}.chapterDetail{height:580px;overflow:auto;padding:0 12px;}.navFirst{line-height:40px;background:url(../../images/nav_default.png) repeat-y;margin-bottom:4px;background-size:100%;}.navFirst a{display:block;color:#fff;text-align:left;text-align:left;cursor:pointer;}.left{text-align:center;width:100%;}.left>ul>li{line-height:40px;margin-bottom:1px;margin-top:1px;background-size:100%;}.left>ul>li>a{display:block;color:#333;text-align:left;}.left>ul>li>a .down{background:url(../../images/ico_courseAdd.png) no-repeat;background-position:12px 15px;display:block;padding-left:40px;}.left>ul>li>a .up{background:url(../../images/ico_courseMinus.png) no-repeat;background-position:12px 15px;display:block;padding-left:40px;}.left>ul>li>ul{display:none}.left>ul>li>ul>li{line-height:30px;margin-bottom:1px;margin-top:1px;position:relative;}.left>ul>li>ul>li i{left:17%;position:absolute;top:0;font-size:14px;}.left>ul>li>ul>li>a{display:block;color:#333;text-align:left;padding-left:30%;font-size:14px;}.left>ul>li>a[data-value=\'1\']{display:block;color:#72a3e3;text-align:left;}.left>ul>li>ul>li>a img{width:16px;height:16px;margin-top:6px;margin-right:6%;display:none;}.left>ul>li>ul>li>a:hover{background:#eaf4fe;}.left>ul>li>ul>li>a:hover img{display:block;}video{object-fit:fill;width:100%;height:100%;position:absolute;left:0;top:0;background:#fff  url(../../images/ad_videoResource.jpg) no-repeat center;}video::-internal-media-controls-download-button{display:none;}video::-webkit-media-controls-enclosure{overflow:hidden;}video::-webkit-media-controls-panel{width:calc(100% + 30px);}.fileName{width:188px;height:24px;margin:0 auto;font-size:14px;color:#999999;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}.fileBtn{width:122px;height:24px;margin:58px auto 0;text-align:right;font-size:16px;display:block;line-height:24px;color:#333;background:#fff url(../../images/ico_classadd.png) left center no-repeat;}.exportBtn{width:114px;height:43px;color:#fff;border-radius:5px;font-size:16px;}.exportBtn:hover{background:#aa2011;color:#fff;}.popup{display:block;z-index:1;}.mb{z-index:1;}.pophomework{top:20%;width:30%;position:absolute;left:35%;background:#fff;background:#fff;display:none;border-radius:5px;display:block;z-index:1;}.popup_content{width:80%;margin:20px auto;font-size:16px;height:auto;}.popup_content i{float:left;font-weight:700;}.popup_content span{width:400px;word-break:break-all;}.popup_btn{margin-top:30px;}.exportBtns{width:114px;height:43px;color:#fff;border-radius:5px;font-size:16px;}.exportBtn{border:none;}.popup_btns{border-radius:0 0 5px 5px;height:60px;margin:0 auto;width:120px;margin:30px auto 0;}.popup_btns a{color:#fff;padding:10px 40px;border-radius:5px;}.popup_btns .popup_close,.popup_btns .popup_confirm{background:#c80211;cursor:pointer;}.popup_btn .popup_close:hover{background:none;}.packProcess{position:absolute;right:4px;top:18px;width:14px;font-size:14px;line-height:1.1;cursor:pointer;text-align:center;}.packProcess img{display:inline;transform:rotate(180deg);}.showProcess{font-size:14px;margin-right:1%;display:none;cursor:pointer;}.showProcess img,.oneChapter img{display:inline;}.oneChapter img{vertical-align:middle;}.moveTop,.moveDown{width:28px;height:55px;position:absolute;top:-14px;left:35%;cursor:pointer;z-index:1;background:url(../../images/nav_move.png) no-repeat center;transform:rotate(90deg);}.moveTop{top:-42px;}.moveDown{transform:rotate(-90deg);display:none;}@media only screen and (max-width:1400px){.left>ul>li>ul>li>a{font-size:11px;}.left>ul>li>ul>li>a img{margin-right:1%;}.left>ul>li>ul>li i{left:11%;position:absolute;top:0;font-size:14px;}}@media only screen and (max-width:1600px){.left>ul>li>ul>li>a{padding-left:30%;}}@media only screen and (max-width:1024px){.processBox{height:110px;width:62%;}.btnBox{width:18%;}}.editSection{position:absolute;z-index:3;width:100%;height:100%;background:#fff url(../../images/ico_chapterMakeBg.png) no-repeat center top 190px;top:0;left:0;}.editSection>div{margin-top:500px;width:100%;text-align:center;}.questionBox{padding:0 32px 10px;}.choseOne{padding:0 15px;margin-bottom:10px;}.trueAnswer{margin-left:25px;color:#c80211;display:none;}.shortAnswer{width:50%;height:130px;resize:none;font-size:16px;padding:20px;display:none;}.downloadExam{position:fixed;bottom:0;left:50%;margin-left:-50px;}.answerInt{width:50px;height:20px;border:none;padding:0 5px;text-align:center;font-size:16px;min-width:50px;word-break:break-all;display:none;}.choseOne .shortAnswer{border:1px solid #cdcdcd;height:100px;width:500px;margin:20px 0;text-align:left;padding:10px;display:none;}.saveMar{width:50px;background:url(../../images/ico_chapterMakeSave.png) no-repeat right center;color:#153364;font-size:14px;font-weight:normal;text-align:left;margin-left:35px;cursor:pointer;margin-bottom:20px;display:none;}.saveMar,.saveHome{display:none}#contentBox{background:#fff;}#contentBox>div{margin:0;}textarea{display:none!important;}'
                                        });
                                        loading1.show();
                                        $.ajax({
                                            type: "post",
                                            url: "uploadTest",
                                            async: true,
                                            data:{
                                              "jsonStr":json
                                            },
                                            success: function (msg) {
                                                loading1.hide();
                                                msg = JSON.parse(msg);
                                                if(msg.result == "success"){
                                                    Alert1.content = "提交成功";
                                                    Alert1.init();
                                                    Alert1.show();
                                                    that.children("em").html("未评价");
                                                    // that.children("img").attr("data-src",msg.stuUrl);
                                                    // that.children("img").attr("style","");
                                                }else{
                                                    Alert1.content = msg.failMsg;
                                                    Alert1.init();
                                                    Alert1.show();
                                                    return false;
                                                }
                                            }
                                        });
                                    });
                                }else{
                                    str = homeworkShow(unescape(msg.chapterMsg.taskHtml));
                                    str = str.replace(/\(\+\)/g,"(&emsp;&emsp;)");
                                    $(".fileShowSection").append("<div>"+str);
                                    $(".homeShowBox").css("overflow","visible");
                                    if($(".fileShowSection ").height()>710){
                                        $(".homeShowBox").css("height","790px");
                                    }else{
                                        $(".homeShowBox").css("height","690px");
                                    }

                                }
                            } else {
                                $showSection.attr("src", "pc/page/noResourceShow.html");
                            }
                        }else{
                            if(msg.failMsg!=undefined){
                                Alert1.content = msg.failMsg;
                            }else{
                                Alert1.content = "获取失败";
                            }
                            Alert1.init();
                            Alert1.show();
                        }
                    }
                });
            });
//			实验手册
            $(".testDoc").off("click").click(function(){
                videoRemove();
                $(".editSection").remove();
                self.addProcess({"chapterNum":$(this).attr("data-chapternum"),"courseId":$(this).attr("data-courseid")});
                $(this).parent().parent().siblings("a").attr("data-value","1");
                if($(this).attr("data-src").indexOf(".html") != -1){
                    $showSection.attr("src",$(this).attr("data-src"));
                }else{
                    $showSection.attr("src","pc/page/noResourceShow.html");
                }

            });
//			学习视频
            $(".video").off("click").click(function(){
                videoRemove();
                $(".editSection").remove();
                self.addProcess({"chapterNum":$(this).attr("data-chapternum"),"courseId":$(this).attr("data-courseid")});
                $(this).parent().parent().siblings("a").attr("data-value","1");
                $showSection.after("<video autoplay controls class='showVideo'  src='"+ $(this).attr("data-src") +"'></video>");
                $('.showVideo').bind('contextmenu',function() { return false; });
                $showSection.load(function () {
                    $showSection.contents().find("link").remove();
                });
            });
            //下载
            $(".download").off("click").click(function(e){
                if($(this).attr("data-src").indexOf("undefined") != -1||$(this).attr("data-src")==url||$(this).attr("data-src")==stuUrl){
                    Alert1.content = "当前没有文件可供下载";
                    Alert1.init();
                    Alert1.show();
                }else{
                    $(this).append("<a href=\""+ $(this).attr("data-src") +"\" download id='downFile'></a>");
                    document.getElementById("downFile").click();
                    $("#downFile").remove();
                    e.stopPropagation();
                }

            });

//			进入实验
            $(".enterLab").off("click").click(function(){
                var that = $(this);
                var flag = false;
                $(this).parent().parent().siblings("a").attr("data-value","1");
                self.addProcess({"chapterNum":Number(that.attr("data-chapternum")),"courseId":Number(that.attr("data-courseid"))});
                self.enterLab(that);
            });
        },
        enterLab:function(opt){
//			进入实验
            var self = this;
            var jsonStr = JSON.stringify({"mark":2,"courseId":Number(opt.attr("data-courseid"))});
            $.ajax({
                type:"post",
                url:"addCourseOrExpreCount",
                async:true,
                data:{
                    "jsonStr":jsonStr
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    if(msg.result == "success"){
                        window.location.href = "skipEnvironment?courseId="+ Number(opt.attr("data-courseid")) +"&chapterId="+  Number(opt.attr("data-chapterid")) +"&chapterNum="+Number(opt.attr("data-chapternum"));
                        $("#ifMain",parent.document).css({"position":"fixed","left":0,"top":0,"z-index":100});
                    }
                }
            });
        },
        addProcess:function(opt){
//			添加进度
            var self = this;
            var jsonStr = JSON.stringify(opt);
            $.ajax({
                type:"post",
                url:"addProcess",
                async:true,
                data:{
                    "jsonStr":jsonStr
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    if(msg.result == "success"){
                        self.getProcess();
                    }
                }
            });
        },
        getProcess:function(){
            //获取学习进度
            var json = JSON.stringify({
                "courseId": result.paramData.courseId,
                "stuorteaId": result.stuorteaId
            });
            $.ajax({
                type:"post",
                url:"getMyProcess",
                async:true,
                data:{
                    "jsonStr":json
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    $processInfo.html("已进行"+ msg.process +"/"+ msg.totalLength +"课时");
                    $processed.animate({
                        width:(msg.process)/(msg.totalLength)*100+"%"
                    },"slow")
                }

            });
        },
        selectEvent:function(){
            /*导航下拉展开事件*/
            $(".left span").click(function() {
                if($(this).hasClass("up")) {
                    $(this).removeClass("up");
                    $(this).addClass("down");
                    $(this).parent().parent().parent().find("ul").slideToggle(300);
                } else {
                    $(".left ul li ul").slideUp(300);
                    $(".left ul li span").removeClass("up");
                    $(".left ul li span").addClass("down");
                    $(this).removeClass("down");
                    $(this).addClass("up");
                    $(this).parent().parent().parent().find("ul").slideToggle(300);
                }
            });
        }
    };
    myCourse.init();
});
